package com.tbit.manager.api.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 运营数据查询传输实体类
 *
 * @Author:BUGTian
 * @DATE: 2022/11/1
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class OperationalDataDTO implements Serializable {

    /**
     * 开始时间
     */
    @NotNull(message = "开始时间不能为空")
    private Date startTime;
    /**
     * 结束时间
     */
    @NotNull(message = "结束时间不能为空")
    private Date endTime;
    /**
     * 品牌id
     */
    @NotNull(message = "品牌不能为空")
    private Integer brandId;
    /**
     * 区域id 多个用,隔开
     */
    private String accountIds;

    /**
     * 获取区域id List
     *
     * @return
     */
    public List<Integer> getAccountIdList() {
        List<Integer> accountIdList = new ArrayList<>();
        if (!StringUtils.hasText(accountIds)) {
            return accountIdList;
        }
        try {
            String[] accountIds = this.accountIds.split(",");
            for (String accountId : accountIds) {
                accountIdList.add(Integer.parseInt(accountId));
            }
        } catch (Exception e) {
            throw new RuntimeException("区域id有误");
        }

        return accountIdList;
    }
}
